package com.qiqv.exception;

import com.qiqv.dto.QiQvResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 定义全局异常处理器
 * @author hjr
 * @version 1.0
 * @date 2023/2/14 11:22
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    
    @ExceptionHandler(ApplicationException.class)
    public QiQvResult exceptionHandler(ApplicationException exception){
        String errorMessage = exception.getErrorMsg();
        return QiQvResult.FAIL(errorMessage);
    }

    @ExceptionHandler(Exception.class)
    public QiQvResult exceptionHandler(Exception exception){
        String errorMessage = exception.getMessage();
        return QiQvResult.FAIL("未知异常-"+errorMessage);
    }
}
